/*
 * aligner.cc
 *
 *  Created on: Dec 2, 2012
 *      Author: hxin
 */

#include "aligner.h"
#include "refAnalyser.h"
#include "twoLvHTAnalyser.h"
#include "common.h"
#include "hashGen.h"

aligner::aligner(string hashFileName, string readFileName, string HTFileName) {
	switch (aligner_config) {
	case FAKE_ALIGN_HET:
		ht = new hashGen(hashFileName, HTFileName, _g_KmerLength);
		cout << "***Here!0" << endl;
		break;
	case FAKE_ALIGN_2LV:
		ht = new twoLvHTAnalyser(hashFileName, _g_shortHTLength);
		break;
	case FAKE_ALIGN_BASE:
		ht = new refAnalyser(hashFileName, _g_shortHTLength);
		break;
	default:
		cerr << "Wrong config" << endl;
		exit(1);
		break;
	}
	readFile.open(readFileName.c_str());
}

aligner::~aligner() {
	delete ht;
	ht = NULL;
	readFile.close();
}

void aligner::loadHT(int chrNum) {
	ht->unloadHash();
	ht->loadHash(chrNum);
}

void aligner::alignChr(int chrNum) {
	loadHT(chrNum);

	string trash, read;

	//read out the first trash
	getline(readFile, trash);
	do {
		getline(readFile, read);
		ht->query(read);

		getline(readFile, trash);
		getline(readFile, trash);
		getline(readFile, trash);
	} while (readFile.good());
}

void aligner::printStat() {
	ht->printStat();
}
